using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Service.IService.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Model.Dto.Business.ProductionControl;

//创建时间：2024-09-29
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 物料规则&BOM清单配置
    /// </summary>
    [Verify]
    [Route("production/materialruleconfig")]
    [ApiExplorerSettings(GroupName = "business")]
    public class MaterialRuleConfigController : BaseController
    {
        /// <summary>
        /// 物料规则配置接口
        /// </summary>
        private readonly IMaterialRuleConfigService _MaterialRuleConfigService;

        public MaterialRuleConfigController(IMaterialRuleConfigService MaterialRuleConfigService)
        {
            _MaterialRuleConfigService = MaterialRuleConfigService;
        }

        /// <summary>
        /// 查询 物料规则配置列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "production:materialruleconfig:list")]
        public IActionResult QueryMaterialRuleConfig([FromQuery] MaterialRuleConfigQueryDto parm)
        {
            var response = _MaterialRuleConfigService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询 物料规则配置详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "production:materialruleconfig:query")]
        public IActionResult GetMaterialRuleConfig(int Id)
        {
            var response = _MaterialRuleConfigService.GetInfo(Id);

            var info = response.Adapt<MaterialRuleConfigDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加 物料规则配置
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "production:materialruleconfig:add")]
        [Log(Title = " 物料规则配置", BusinessType = BusinessType.INSERT)]
        public IActionResult AddMaterialRuleConfig([FromBody] MaterialRuleConfigDto parm)
        {
            var modal = parm.Adapt<MaterialRuleConfig>().ToCreate(HttpContext);

            var response = _MaterialRuleConfigService.AddMaterialRuleConfig(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新 物料规则配置
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "production:materialruleconfig:edit")]
        [Log(Title = " 物料规则配置", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateMaterialRuleConfig([FromBody] MaterialRuleConfigDto parm)
        {
            var modal = parm.Adapt<MaterialRuleConfig>().ToUpdate(HttpContext);
            var response = _MaterialRuleConfigService.UpdateMaterialRuleConfig(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除 物料规则配置
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "production:materialruleconfig:delete")]
        [Log(Title = " 物料规则配置", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteMaterialRuleConfig([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_MaterialRuleConfigService.Delete(idArr));
        }
    }
}